<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>焦点事件</title>
    <style>
        input{
            outline: none;
            width: 100px;
            transition:all .5s;
        }
    </style>
</head>
<body>
    <input type="text" placeholder="请输入商品名称">
    <script>
        let input = document.querySelector("input")
        //获得焦点事件
        input.onfocus = function(){
            this.placeholder = ""
            this.style.width = "150px"
        }
        //失去焦点事件
        input.onblur = function(){
            this.placeholder = "请输入商品名称"
            this.value = this.value.trim()
            this.style.width = "100px"
        }
    </script>
</body>
</html>